//
//  ILSelectionTableViewCell.m
//  ILife
//
//  Created by lanou on 15/10/27.
//  Copyright © 2015年 ILife. All rights reserved.
//

#import "ILSelectionTableViewCell.h"
#import <UIImageView+WebCache.h>
#define BH self.bounds.size.height
#define BW self.bounds.size.width

@implementation ILSelectionTableViewCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
// 图片
        _thumbImgView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, SCREEN_WIDTH - 20, SCREEN_WIDTH - 20)];
        
        
        
// 标题
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, SCREEN_WIDTH*0.7+15, SCREEN_WIDTH-20, SCREEN_WIDTH*0.2)];
        _titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:22];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.numberOfLines = 0;
        
// 标题背景
        _backgroundLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, SCREEN_WIDTH*0.7+15, SCREEN_WIDTH-20, SCREEN_WIDTH*0.2)];
        _backgroundLabel.backgroundColor = [UIColor grayColor];
        _backgroundLabel.alpha = 0.4;
        
// 小标题
        _cat_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 60, 30)];
        _cat_titleLabel.font = [UIFont systemFontOfSize:14];
        _cat_titleLabel.textColor = [UIColor whiteColor];

// 时间
        _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH*0.8, 10, 80, 30)];
        _timeLabel.textColor = [UIColor whiteColor];
        _timeLabel.font = [UIFont systemFontOfSize:12];
        
        
// 描述
        _descpLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, SCREEN_WIDTH-10, SCREEN_WIDTH - 20, 40)];
        _descpLabel.font = [UIFont systemFontOfSize:14];
        _descpLabel.numberOfLines = 0;
        
        
        [_thumbImgView addSubview:_backgroundLabel];
        [_thumbImgView addSubview:_titleLabel];
        [_thumbImgView addSubview:_cat_titleLabel];
        [_thumbImgView addSubview:_timeLabel];
        [self.contentView addSubview:_thumbImgView];
        [self.contentView addSubview:_descpLabel];
        
        
        
    }
    return self;
    
}

- (void)setConfiguer:(ILHomePageModel *)configuer
{
    _configuer = configuer;
    
// 图片
    [_thumbImgView sd_setImageWithURL:[NSURL URLWithString:configuer.thumb]placeholderImage:[UIImage imageNamed:@"ilife"]];
    _thumbImgView.frame = CGRectMake(10, 10, SCREEN_WIDTH-20, SCREEN_WIDTH-20);
    
// 标题
    _titleLabel.text = configuer.title;
    _titleLabel.frame = CGRectMake(0, SCREEN_WIDTH*0.7+15, SCREEN_WIDTH-20, SCREEN_WIDTH*0.2);

// 小标题
    _cat_titleLabel.text = configuer.cat_title;
    _cat_titleLabel.frame = CGRectMake(10, 10, 90, 30);
    
// 时间
    _timeLabel.text = configuer.published;
    _timeLabel.frame = CGRectMake(SCREEN_WIDTH*0.7, 10, 70, 30);
    
// 描述
    _descpLabel.text = configuer.descrip;
    _descpLabel.frame = CGRectMake(10, SCREEN_WIDTH - 5, SCREEN_WIDTH - 20, [ILSelectionTableViewCell heightofString:_descpLabel.text Font:[UIFont systemFontOfSize:14]]);

}


// 自定义cell高度
+ (CGFloat)heightofString:(NSString *)string Font:(UIFont *)font
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    CGRect bounds = [string boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return bounds.size.height;
}




+(CGFloat)heightOfCell:(ILHomePageModel *)model
{
    return SCREEN_WIDTH + [ILSelectionTableViewCell heightofString:model.descrip Font:[UIFont systemFontOfSize:14]];
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
